package com.situ.mymall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.mymall.mapper.CartMapper;
import com.situ.mymall.pojo.entity.Cart;
import com.situ.mymall.pojo.query.CartQuery;
import com.situ.mymall.pojo.vo.CartVO;
import com.situ.mymall.service.ICartService;
import com.situ.mymall.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CartServiceImpl implements ICartService {

    @Autowired
    private CartMapper cartMapper;

    @Override
    public PageResult list(CartQuery cartQuery) {
        PageHelper.startPage(cartQuery.getPage(), cartQuery.getLimit());
        List<CartVO> list = cartMapper.list(cartQuery);
        PageInfo pageInfo = new PageInfo(list);
        int totalCount = (int) pageInfo.getTotal();

        return PageResult.ok(totalCount,list);
    }

    @Override
    public Cart selectById(Integer id) {
        return cartMapper.selectByPrimaryKey(id);
    }

    @Override
    public void add(Cart cart) {
        cartMapper.updateByPrimaryKeySelective(cart);
    }

    @Override
    public void deleteById(Integer id) {
        cartMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void deleteAll(Integer[] ids) {
        cartMapper.deleteAll(ids);
    }

    @Override
    public void update(Cart cart) {
        cartMapper.updateByPrimaryKeySelective(cart);
    }

    @Override
    public void updateStatus(Cart cart) {
        cartMapper.updateStatus(cart);
    }
}
